/**
 * Created by jiangtao on 16/7/5.
 */

let webpack = require('webpack');

let AssetsPlugin = require('assets-webpack-plugin');

let CleanWebpackPlugin = require('clean-webpack-plugin');

let baseConfig = require('./webpack.base.config');

let process = require("process");

let WebpackMd5Hash = require('webpack-md5-hash');

let prodConfig = {
    plugins: [
        new webpack.HashedModuleIdsPlugin(),
        new WebpackMd5Hash(),
        new webpack.optimize.OccurrenceOrderPlugin(true),
        //js压缩参数
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false,
                drop_console: true
            },
            beautify: false,
            comments: false
        }),
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"production"'
            }
        }),
        new webpack.LoaderOptionsPlugin({
            minimize: true
        }),
        new AssetsPlugin({
            filename: "asset-map.json",
            processOutput: function (assets) {
                let common = assets.common;
                let page = {};
                for (let key in assets) {
                    if (key !== "common") {
                        page[key] = {
                            css: [
                                common.css,
                                assets[key].css
                            ],
                            js: [
                                common.js,
                                assets[key].js
                            ]
                        }
                    }
                }
                return JSON.stringify(page);
            }
        }),
        new CleanWebpackPlugin(
            ['dist'],　 //匹配删除的文件
            {
                root: __dirname,//根目录
                verbose: true,//开启在控制台输出信息
                dry: false//启用删除文件
            }
        )
    ]
};

baseConfig.output.publicPath = "http://yutao2012.com/wymusic/";

baseConfig.plugins = prodConfig.plugins.concat(baseConfig.plugins);

module.exports = baseConfig;